package com.wfc.servlet.dish;

import com.wfc.entity.Cook;
import com.wfc.service.CookService;
import com.wfc.service.serviceImpl.CookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/canpuSelvet")
public class CanpuServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String name=req.getParameter("name");
        resp.setContentType("text/html;charset=utf-8");
        HttpSession session = req.getSession();
        CookService cookService = new CookServiceImpl();
        PrintWriter printWriter=resp.getWriter();
        String rep = "1";
        Cook cook = cookService.selectByimg(name);
        //菜
        String dname = cook.getDname();


        session.setAttribute("cook",cook);
        //菜谱的制作图片
        String cooking = cook.getCooking();
        if("null".equals(cooking)){
            String[] imgs = cooking.split("&");
            session.setAttribute("cookingimgs",imgs);
        }
        //菜谱的主食
        String mainfood = cook.getMainfood();
        if("null".equals(mainfood)){
            String[] mainfoods = mainfood.split("&");
            session.setAttribute("mainfoods",mainfoods);
        }


        //菜谱的辅食
        String fufood = cook.getFufood();
        if("null".equals(fufood)){
            String[] fufoods = fufood.split("&");
            session.setAttribute("fufoods",fufoods);
        }

        //菜谱的调料
        String tiaofood = cook.getTiaofood();
        if("null".equals(tiaofood)){
            String[] tiaofoods = tiaofood.split("&");
            session.setAttribute("tiaofoods",tiaofoods);
        }

        //菜谱的 酸辣。。。。
        String process = cook.getProcess();
        if("null".equals(process)){
            String[] processs = process.split("&");
            session.setAttribute("processs",processs);
        }

        //菜谱的制作步骤
        String cookText = cook.getCooktext();
        if ("null".equals(cookText)){
            String[] cookTexts = cookText.split("&");
            session.setAttribute("cookTexts",cookTexts);
        }


        printWriter.println(rep);

        printWriter.flush();
        printWriter.close();

    }
}
